﻿<UserControl x:Class="Samba.Modules.TicketModule.MenuItemSelectorView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:Common="clr-namespace:Samba.Presentation.Common;assembly=Samba.Presentation.Common"
     xmlns:FxButton="clr-namespace:FlexButton;assembly=FlexButton" mc:Ignorable="d" d:DesignHeight="300"
     d:DesignWidth="300">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <ItemsControl MaxHeight="70" Grid.Row="0" ItemsSource="{Binding MostUsedMenuItems}">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <UniformGrid Rows="1" Columns="{Binding MostUsedItemsCategory.ColumnCount}" />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <FxButton:FlexButton Margin="5,0,0,7" Focusable="False" ButtonColor="{Binding ButtonColor}"
                         ButtonImage="{Binding ImagePath}" Content="{Binding Caption}" Command="{Binding Command}"
                         CommandParameter="{Binding ScreenMenuItem}" />
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
        <Grid Name="MainGrid" Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="22*" />
                <ColumnDefinition Width="78*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="auto" />
                <RowDefinition Height="60*" />
                <RowDefinition Height="40*" Name="NumeratorRow" />
            </Grid.RowDefinitions>
            <ScrollViewer Grid.RowSpan="3" Grid.Column="0" Margin="7,0,7,1" Common:KineticBehaviour.HandleKineticScrolling="True"
                 VerticalScrollBarVisibility="Auto">
                <ItemsControl ItemsSource="{Binding Categories,NotifyOnTargetUpdated=True}" TargetUpdated="ItemsControl_TargetUpdated">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <UniformGrid Columns="1" VerticalAlignment="{Binding CategoriesVerticalAlignment}" />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <FxButton:FlexButton Content="{Binding Caption}" Focusable="False" Command="{Binding ButtonCommand}"
                                 CommandParameter="{Binding Category}" Height="{Binding MButtonHeight}" Margin="0,0,0,0"
                                 ButtonImage="{Binding ImagePath}" ButtonColor="{Binding MButtonColor}" />
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </ScrollViewer>
            <ListBox MinHeight="60" Grid.Row="0" Grid.Column="1" BorderThickness="0" Background="Transparent"
                 Visibility="{Binding IsQuickNumeratorVisible,Converter={StaticResource VisibilityConverter}}"
                 ItemsSource="{Binding QuickNumeratorValues}" SelectedItem="{Binding NumeratorValue,Mode=TwoWay}">
                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <UniformGrid Rows="1" />
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Viewbox>
                                <TextBlock FontWeight="Bold" Text="{Binding}" />
                            </Viewbox>
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
                <ListBox.Resources>
                    <SolidColorBrush x:Key="DisabledForegroundBrush" Color="#888" />
                    <Style TargetType="ListBoxItem">
                        <Setter Property="SnapsToDevicePixels" Value="true" />
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="ListBoxItem">
                                    <Border Margin="0,0,4,4" Background="WhiteSmoke" Name="Border" BorderThickness="1"
                                         CornerRadius="4" BorderBrush="Gray">
                                        <ContentPresenter />
                                    </Border>
                                    <ControlTemplate.Triggers>
                                        <Trigger Property="IsSelected" Value="true">
                                            <Setter TargetName="Border" Property="BorderThickness" Value="2" />
                                            <Setter Property="Foreground" Value="Red" />
                                        </Trigger>
                                        <Trigger Property="IsEnabled" Value="false">
                                            <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}" />
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </ListBox.Resources>
            </ListBox>
            <Grid Grid.Row="1" Grid.Column="1">
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <ItemsControl Grid.Row="0"  ItemsSource="{Binding SubCategories,NotifyOnTargetUpdated=True}">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <UniformGrid Rows="1" />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <FxButton:FlexButton Content="{Binding Caption}" Focusable="False" Command="{Binding Command}"
                                 CommandParameter="{Binding }" Height="{Binding Height}" Margin="0,0,0,5" ButtonColor="{Binding ButtonColor}"/>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
                <ScrollViewer Grid.Row="1" Common:KineticBehaviour.HandleKineticScrolling="True"
                 VerticalScrollBarVisibility="Auto">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="auto" />
                        </Grid.RowDefinitions>
                        <ItemsControl ItemsSource="{Binding MenuItems,NotifyOnTargetUpdated=True}" HorizontalAlignment="Stretch"
                         TargetUpdated="ItemsControl_TargetUpdated_1">
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <UniformGrid Columns="{Binding SelectedCategory.ColumnCount}" VerticalAlignment="{Binding MenuItemsVerticalAlignment}" />
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <FxButton:FlexButton IsImageOnly="{Binding IsImageOnly}" Focusable="False" ButtonColor="{Binding ButtonColor}" Content="{Binding Caption}"
                                     Command="{Binding Command}" CommandParameter="{Binding ScreenMenuItem}" Height="{Binding ButtonHeight}"
                                      Margin="0,0,0,0" ButtonImage="{Binding ImagePath}"/>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                        <UniformGrid Grid.Row="1" Columns="2" Rows="1" Visibility="{Binding IsPageNumberNavigatorVisible,Converter={StaticResource VisibilityConverter}}">
                            <FxButton:FlexButton Margin="0,3,3,3" Height="45" Command="{Binding DecPageNumberCommand}"
                             Content="{Binding DecPageNumberCommand.Caption}" />
                            <FxButton:FlexButton Margin="0,3,0,3" Height="45" Command="{Binding IncPageNumberCommand}"
                             Content="{Binding IncPageNumberCommand.Caption}" />
                        </UniformGrid>
                    </Grid>
                </ScrollViewer>
            </Grid>

            <Grid Grid.Column="1" Grid.Row="2" Visibility="{Binding IsNumeratorVisible,Converter={StaticResource VisibilityConverter}}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="*" />
                    <RowDefinition Height="auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="3*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Grid Grid.ColumnSpan="2" Grid.Row="0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="auto" />
                    </Grid.ColumnDefinitions>
                    <TextBox IsReadOnly="True" Focusable="false" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="3"
                         FontSize="30" FontWeight="Bold" Text="{Binding NumeratorValue,Mode=TwoWay}" />
                    <FxButton:FlexButton MinWidth="40" Grid.Column="3" Grid.Row="0" Content='C' Command="{Binding TypeValueCommand}"
                         CommandParameter="C" Margin="2,0,0,2" Focusable="False" />
                </Grid>
                <UniformGrid Grid.Column="0" Grid.Row="1" Rows="4" Columns="3">
                    <FxButton:FlexButton Content="1" Command="{Binding TypeValueCommand}" CommandParameter="1"
                         Margin="0,0,2,2" Focusable="False" />
                    <FxButton:FlexButton Content="2" Command="{Binding TypeValueCommand}" CommandParameter="2"
                         Margin="0,0,2,2" Focusable="False" />
                    <FxButton:FlexButton Content="3" Command="{Binding TypeValueCommand}" CommandParameter="3"
                         Margin="0,0,2,2" Focusable="False" />
                    <FxButton:FlexButton Content="4" Command="{Binding TypeValueCommand}" CommandParameter="4"
                         Margin="0,0,2,2" Focusable="False" />
                    <FxButton:FlexButton Content="5" Command="{Binding TypeValueCommand}" CommandParameter="5"
                         Margin="0,0,2,2" Focusable="False" />
                    <FxButton:FlexButton Content="6" Command="{Binding TypeValueCommand}" CommandParameter="6"
                         Margin="0,0,2,2" Focusable="False" />
                    <FxButton:FlexButton Content="7" Command="{Binding TypeValueCommand}" CommandParameter="7"
                         Margin="0,0,2,2" Focusable="False" />
                    <FxButton:FlexButton Content="8" Command="{Binding TypeValueCommand}" CommandParameter="8"
                         Margin="0,0,2,2" Focusable="False" />
                    <FxButton:FlexButton Content="9" Command="{Binding TypeValueCommand}" CommandParameter="9"
                         Margin="0,0,2,2" Focusable="False" />
                    <FxButton:FlexButton Content="," Command="{Binding TypeValueCommand}" CommandParameter=","
                         Margin="0,0,2,2" Focusable="False" />
                    <FxButton:FlexButton Content="0" Command="{Binding TypeValueCommand}" CommandParameter="0"
                         Margin="0,0,2,2" Focusable="False" />
                    <FxButton:FlexButton Content="x" Command="{Binding TypeValueCommand}" CommandParameter="x"
                         Margin="0,0,2,2" Focusable="False" />
                </UniformGrid>
                <UniformGrid Grid.Row="1" Grid.Column="2" Columns="1" Grid.RowSpan="2">
                    <FxButton:FlexButton Margin="0,0,0,2" Command="{Binding FindMenuItemCommand}" Focusable="False">
                        <LocText ResourceIdentifierKey="FindProduct"/>
                    </FxButton:FlexButton>
                    <FxButton:FlexButton Margin="0,0,0,2" Command="{Binding FindTicketCommand}" Focusable="False">
                        <LocText ResourceIdentifierKey="FindTicket"/>
                    </FxButton:FlexButton>
                    <FxButton:FlexButton Margin="0,0,0,2" Command="{Binding FindTableCommand}" Focusable="False">
                        <LocText ResourceIdentifierKey="FindTable"/>
                    </FxButton:FlexButton>
                </UniformGrid>
                <ItemsControl Grid.Row="2" Grid.Column="0" ItemsSource="{Binding AlphaButtonValues}">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <UniformGrid Rows="1" />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <FxButton:FlexButton MaxHeight="40" Focusable="False" Margin="0,0,2,2" Content="{Binding}"
                                 CommandParameter="{Binding}" Command="{Binding DataContext.TypeValueCommand,RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}, Mode=FindAncestor}}" />
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </Grid>
        </Grid>
    </Grid>
</UserControl>